import { HomeContainerService } from '../../service/home-container-service/index';
import { map } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { emoji } from 'src/app/shared/annotation/test';
import { CarouselData, Channel } from 'src/app/shared/components';
import { Ad, ProductList } from 'src/app/shared/domain';
import { Router } from '@angular/router';
interface Ip {
  adcode: number;
  city: string;
  province: string;
  status: string;
}
@Component({
  selector: 'app-home-recommend',
  templateUrl: './home-recommend.component.html',
  styleUrls: ['./home-recommend.component.less'],
})
export class HomeRecommendComponent implements OnInit {
  @emoji()
  result: string = 'hello';
  endTime: Date = new Date('2021-6-7');
  data$: Observable<any> | undefined;
  ads$!: Observable<Ad>;
  sliders: CarouselData[] = [
    {
      link: 'https://s.click.taobao.com/t?union_lens=lensId%3AOPT%401622098201%402108254e_07d1_179ac964a3b_b6b2%4001%3BeventPageId%3A20150318020005343&e=m%3D2%26s%3D9W28BLoo4eAcQipKwQzePCperVdZeJviePMclkcdtjxyINtkUhsv0PFNY2o%2F3gfEJSon%2F5PVSnZD415GGSsrJ4YxhNUZ2i3GTlT4SLzYDiCfCXHup5K%2Bijvflh4%2Fhqj89CGjsatFbg%2FkxFiXT%2FI5kRN%2BdOc3deN51fMlgiw%2FKpyHWWrZt0BFT1Dze88kSTrMawU4uERFk5RqaQUd0gXF40ZIrDWvWZgOWPQUs5CccI%2F6mYqlkjLgPCGFCzYOOqAQ&pid=mm_0_0_0',
      imageUrl:
        'https://img.alicdn.com/imgextra/i1/O1CN01NbSlhN1v9aYyqzP0L_!!6000000006130-0-tps-520-280.jpg',
    },
    {
      link: 'https://s.click.taobao.com/t?union_lens=lensId%3AOPT%401612256136%400b1a25e7_ad17_17761f44e98_79f8%4001%3BeventPageId%3A20150318020003696&e=m%3D2%26s%3DqvcPvKpqWgQcQipKwQzePCperVdZeJviPI5Rhak06vatZmRqFOmrPjtQI2ptbj8xMDu9fLXmIlmiB9z1SEcjSW%2F4cJGVB8O23dPr9tqBe91EtQN0aRNMFQz8VqANvwwT6zGLzGsVVSpEiFenDNcIzk9%2FYFgWEAd0SDsCym4%2BXYF%2BPGXoAieI2mY9hpAAaXcfJY3ISjGZklSSdgXhQ%2BavP9jHk6Ajv4fplzKq68Bj%2Byht13y7RnE5%2FM2jrT2jN9cyaWHun%2FdHq1BP1ply%2Ft95%2F1LhvsiknOOtyLaDP8WIAryH7KeLwQR0PrKSOGd3QcHiE9jysaCX1rw1qu%2BfA3d8iapZ7H3IF6kUxiXvDf8DaRs%3D&pid=mm_0_0_0',
      imageUrl:
        'https://img.alicdn.com/imgextra/i3/O1CN01Izoiln1FXD71sCJI7_!!6000000000496-0-tps-520-280.jpg_q75.jpg_.webp',
    },
    {
      link: 'https://click.mz.simba.taobao.com/ecpm?e=UnKAjDchMyEUe2%2FJ3oPSv%2Fe3q39VhPTbEsFSoYH4GcQ26g4gck%2BRrA0nSh0HWr0fHWFBcd8jszE8gpH1c7RJOI9Q1Cit6rsqtbR9sxq9q4jPdxtGLmpJMATE2Vszfxg%2FIpJR84UDV22ZZKGujfW7%2BSF%2BSjUzRJ0iyTV1QIhaeoFtdxOZ%2BUwbgQOsIye8CQPTAclg1IJUZZgaq2LZWBKZFGRDrS8ac43A74LmTBzXu8h2jhv7rTDQB8SRgm7xBRcTagZouxgK4YtHkmd6UiUyanZtVnNKPXDfLs43Y1oJ35wYx5%2FBePME%2FESeJCVANaMJjyC3Vt060dalAZ4kH6isw9tMCJHd59znQvPNv8D6vW1C882%2FwPq9bULXoZEPPjHtvEGYjG5zHEGmaqZPFbg12lf%2BSEsfnroqTky4KWwYlc%2FrG%2B2DuW7Qim20NmKkt9iJRNInEltvIZyvK3Sl1R7dqiE4aRLrs9u1IThpEuuz27X62nCV3tWN7kWEd5wXC9rkF1vLpuWsBnprOdFSa5XercINcRkuaDTKZEVsMdVdvnz7EHbuy3F0eiwrmRgEy%2BalsmXlhrQVbMYW2wwwY4B1KG9ivudTfk7%2F%2FQoHxxromsX0cO2yjFF5pG6gP0QvjMgIeCta9dO9MibAdcDcZ4WnJ7Vpqa7z%2BHPakJwFemTKX4%2F8ogFG0R59Av%2FT7Df7UA11k9UgDxR%2Bx07WkWBs84OBZQ%3D%3D&u=https%3A%2F%2Fitem.taobao.com%2Fitem.htm%3Fid%3D529033645048&k=729',
      imageUrl:
        'https://aecpm.alicdn.com/imgextra/i4/685508764/O1CN01engzUB2EbxnXwOvZl_!!685508764-0-alimamazszw.jpg',
    },
    {
      link: '',
      imageUrl:
        'https://img.alicdn.com/imgextra/i3/O1CN01lgSJQY1E1Jw3tRfTO_!!6000000000291-2-tps-520-280.png',
    },
    {
      link: 'https://s.click.taobao.com/t?union_lens=lensId%3AOPT%401621824701%4021070895_07d2_1799c4902c6_8b15%4001%3BeventPageId%3A20150318020005215&e=m%3D2%26s%3D3KFmtJEmmKNw4vFB6t2Z2iperVdZeJviePMclkcdtjxyINtkUhsv0AHEOC76dgVZuOcp2797ewxD415GGSsrJ4YxhNUZ2i3GtfcNNJWtX5NUQFyFQJCQKzvflh4%2Fhqj89CGjsatFbg%2FkxFiXT%2FI5kdv2ej9RFznDujXyQ8P5hEAW95D0t3aOisosmJjNa%2FrGYpyF7ku%2BxKjfv8uao0UzJXPBLpVOnUkgCJOWL19NbPBGj2w3bRvM8r8ypPhJ4ccwpMc1VGrcQ1XWbI3zAaDbDQgY3cNma6nxEdnGwy5LTy4iDnp2JBSF2ggVNn9y%2Fp7ccnp8ukjBBR6Gov7fBGHDgRGSqFLGtWntxgxdTc00KD8%3D&pid=mm_0_0_0',
      imageUrl:
        'https://img.alicdn.com/imgextra/i3/O1CN01h7E1p71amsboCY070_!!6000000003373-0-tps-520-280.jpg',
    },
    {
      link: 'https://www.etao.com/cjfl/info.htm?activityId=1593754',
      imageUrl:
        'https://img.alicdn.com/imgextra/i4/O1CN01wrRFUw22CWPWX5i0g_!!6000000007084-2-tps-520-280.png',
    },
  ];
  channel: Channel[] = [
    {
      src: '../assets/time.png',
      title: '限时秒杀',
    },
    {
      src: '../assets/drinks.png',
      title: '饮料',
    },
    {
      src: '../assets/sucai.png',
      title: '蔬菜水果',
    },
    {
      src: '../assets/discount.png',
      title: '限时折扣',
    },
    {
      src: '../assets/time.png',
      title: '限时秒杀',
    },
    {
      src: '../assets/drinks.png',
      title: '饮料',
    },
    {
      src: '../assets/sucai.png',
      title: '蔬菜水果',
    },
    {
      src: '../assets/discount.png',
      title: '限时折扣',
    },
    {
      src: '../assets/time.png',
      title: '限时秒杀',
    },
    {
      src: '../assets/drinks.png',
      title: '饮料',
    },
    {
      src: '../assets/sucai.png',
      title: '蔬菜水果',
    },
    {
      src: '../assets/discount.png',
      title: '限时折扣',
    },
    {
      src: '../assets/time.png',
      title: '限时秒杀',
    },
    {
      src: '../assets/drinks.png',
      title: '饮料',
    },
    {
      src: '../assets/sucai.png',
      title: '蔬菜水果',
    },
    {
      src: '../assets/discount.png',
      title: '限时折扣',
    },
  ];
  constructor(
    private http: HttpClient,
    private data: HomeContainerService,
    private router: Router
  ) {}
  ngOnInit() {
    this.getData();
    this.getAds();
  }
  getData() {
    const observable = this.http.get<Ip>('https://restapi.amap.com/v3/ip', {
      params: {
        ip: '114.247.50.2',
        key: '3bdd72a59ce0d408acc02ecd490edee4',
      },
    });
    this.data$ = observable.pipe(
      map((data) => {
        data.city = '北京城';
        return data;
      })
    );
  }
  getAds() {
    this.ads$ = this.data.getAds();
  }
  handleCardClick(item: ProductList) {
    console.log(item);
    this.router.navigate(['product', item.id]);
  }
}
